<?php

/**
 * 城市/区/商圈数据 ajax获取
 * 
 * @copyright xinwei
 * @since 2012-04-20
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();

function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	//餐厅ID
	cgi::both($g_cgival["id"], "id", 0);
	$g_cgival["id"] = intval($g_cgival["id"]);
	
	//餐厅名称
	cgi::both($g_cgival["type"], "type", "city");
	$g_cgival["type"] = string::un_script_code($g_cgival["type"]);
	$g_cgival["type"] = string::un_html($g_cgival["type"]);
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	$db = new db_eat_area();
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	
	switch($g_cgival["type"])
	{
		case "city":
			$data = $db->admin_get_city_by_site_id($site_id);
			break;
		case "region":
			$data = $db->admin_get_region_by_city_id($g_cgival["id"],$site_id);
			break;
		case "area":
//			$info = $db->admin_get_one_by_id($g_cgival["id"]);
			$data = $db->admin_get_area_by_region_id($g_cgival["id"],$site_id);
			break;
	}
	
	
	$g_show["data"] = $data;
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	
	echo output::json('json',$g_show);
}

?>